﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:params="http://schemas.codeplex.com/elysium/params"
                                   xmlns:controls="clr-namespace:Framework.UI.Controls">
    <ResourceDictionary.MergedDictionaries>
        <controls:SharedResourceDictionary Source="/Framework.UI;component/Themes/WPF/Base/Converter.xaml"/>
        <controls:SharedResourceDictionary Source="/Framework.UI;component/Themes/WPF/Base/Brush.xaml"/>
        <controls:SharedResourceDictionary Source="/Framework.UI;component/Themes/WPF/Base/FocusVisualStyle.xaml"/>
        <controls:SharedResourceDictionary Source="/Framework.UI;component/Themes/WPF/Base/Validation.xaml"/>
        <controls:SharedResourceDictionary Source="/Framework.UI;component/Themes/WPF/Controls/Expander.xaml"/>
        <controls:SharedResourceDictionary Source="/Framework.UI;component/Themes/ElysiumExtra/BorderFix.xaml"/>
    </ResourceDictionary.MergedDictionaries>
    
    <PathGeometry x:Key="TreeArrow" Figures="M0,0 L0,6 L6,0 z"/>
    
    <Style x:Key="ExpandCollapseToggleStyle" TargetType="{x:Type ToggleButton}">
        <Setter Property="Focusable" Value="False"/>
        <Setter Property="Width" Value="16"/>
        <Setter Property="Height" Value="16"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ToggleButton}">
                    <Border Background="{StaticResource TransparentBrush}" Height="16" Padding="5,5,5,5" Width="16">
                        <Path x:Name="ExpandPath" Data="{StaticResource TreeArrow}" Fill="{StaticResource TransparentBrush}" Stroke="#FF989898">
                            <Path.RenderTransform>
                                <RotateTransform Angle="135" CenterY="3" CenterX="3"/>
                            </Path.RenderTransform>
                        </Path>
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsMouseOver" Value="True">
                            <Setter Property="Stroke" TargetName="ExpandPath" Value="#FF1BBBFA"/>
                            <Setter Property="Fill" TargetName="ExpandPath" Value="{StaticResource TransparentBrush}"/>
                        </Trigger>
                        <Trigger Property="IsChecked" Value="True">
                            <Setter Property="RenderTransform" TargetName="ExpandPath">
                                <Setter.Value>
                                    <RotateTransform Angle="180" CenterY="3" CenterX="3"/>
                                </Setter.Value>
                            </Setter>
                            <Setter Property="Fill" TargetName="ExpandPath" Value="#FF595959"/>
                            <Setter Property="Stroke" TargetName="ExpandPath" Value="#FF262626"/>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
    
    <Style TargetType="{x:Type TreeViewItem}">
        <Setter Property="Validation.ErrorTemplate" Value="{StaticResource ValidationErrorControlTemplate}"/>
        <Setter Property="Background" Value="{StaticResource TransparentBrush}"/>
        <Setter Property="BorderBrush" Value="{StaticResource TransparentBrush}"/>
        <Setter Property="BorderThickness" Value="0"/>
        <Setter Property="HorizontalContentAlignment" Value="{Binding HorizontalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/>
        <Setter Property="VerticalContentAlignment" Value="{Binding VerticalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/>
        <Setter Property="Padding" Value="1,0,0,0"/>
        <Setter Property="Foreground" Value="{StaticResource ForegroundBrush}"/>
        <Setter Property="FocusVisualStyle" Value="{StaticResource {x:Static SystemParameters.FocusVisualStyleKey}}"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type TreeViewItem}">
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition MinWidth="19" Width="Auto"/>
                            <ColumnDefinition Width="*"/>
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition/>
                        </Grid.RowDefinitions>
                        <ToggleButton x:Name="Expander" 
                                      ClickMode="Press" 
                                      IsChecked="{Binding IsExpanded, RelativeSource={RelativeSource TemplatedParent}}" 
                                      Style="{StaticResource ExpandCollapseToggleStyle}"/>
                        <controls:BorderFix x:Name="Bd" 
                                Grid.Column="1" 
                                Background="{TemplateBinding Background}"
                                BorderBrush="{TemplateBinding BorderBrush}"
                            BorderThickness="{TemplateBinding BorderThickness}"
                                HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                Padding="{TemplateBinding Padding}" 
                                SnapsToDevicePixels="true">
                            <ContentPresenter x:Name="PART_Header" 
                                                  ContentSource="Header"  
                                                  SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
                        </controls:BorderFix>
                        <ItemsPresenter x:Name="ItemsHost" Grid.Column="1" Grid.Row="1"/>
                    </Grid>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsExpanded" Value="false">
                            <Setter Property="Visibility" TargetName="ItemsHost" Value="Collapsed"/>
                        </Trigger>
                        <Trigger Property="HasItems" Value="false">
                            <Setter Property="Visibility" TargetName="Expander" Value="Hidden"/>
                        </Trigger>
                        <Trigger Property="IsSelected" Value="true">
                            <Setter Property="Background" Value="{StaticResource AccentBrush}"/>
                            <Setter Property="Foreground" Value="{StaticResource ContrastBrush}"/>
                        </Trigger>
                        <MultiTrigger>
                            <MultiTrigger.Conditions>
                                <Condition Property="IsSelected" Value="true"/>
                                <Condition Property="IsSelectionActive" Value="false"/>
                            </MultiTrigger.Conditions>
                            <Setter Property="Background" Value="{StaticResource LowlightBrush}"/>
                            <Setter Property="Foreground" Value="{StaticResource ContrastBrush}"/>
                        </MultiTrigger>
                        <Trigger Property="IsEnabled" Value="false">
                            <Setter Property="Foreground" Value="{StaticResource DisabledBrush}"/>
                            <Setter Property="Foreground" Value="{StaticResource ContrastBrush}"/>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
        <Style.Triggers>
            <Trigger Property="VirtualizingPanel.IsVirtualizing" Value="true">
                <Setter Property="ItemsPanel">
                    <Setter.Value>
                        <ItemsPanelTemplate>
                            <VirtualizingStackPanel/>
                        </ItemsPanelTemplate>
                    </Setter.Value>
                </Setter>
            </Trigger>
        </Style.Triggers>
    </Style>

    <Style x:Key="GraphTreeViewItemStyle" BasedOn="{StaticResource {x:Type TreeViewItem}}" TargetType="{x:Type TreeViewItem}">
        <Setter Property="Background" Value="{StaticResource LowlightBrush}"/>
        <Setter Property="BorderBrush" Value="{StaticResource LowlightBrush}"/>
        <Setter Property="BorderThickness" Value="0"/>
        <Setter Property="FocusVisualStyle" Value="{StaticResource {x:Static SystemParameters.FocusVisualStyleKey}}"/>
        <Setter Property="Foreground" Value="{StaticResource ContrastBrush}"/>
        <Setter Property="Padding" Value="{Binding RelativeSource={RelativeSource Self}, Path=(params:General.BoldPadding), Mode=OneWay}"/>
        <Setter Property="ItemsPanel">
            <Setter.Value>
                <ItemsPanelTemplate>
                    <StackPanel Orientation="Horizontal"/>
                </ItemsPanelTemplate>
            </Setter.Value>
        </Setter>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type TreeViewItem}">
                    <StackPanel>
                        <Rectangle Fill="{TemplateBinding BorderBrush}" 
                                   HorizontalAlignment="Center" 
                                   Height="14" 
                                   SnapsToDevicePixels="True" 
                                   Width="1"/>
                        <Expander x:Name="Expander" 
                                  Background="{TemplateBinding Background}"
                                  BorderBrush="{TemplateBinding BorderBrush}"
                                  BorderThickness="{TemplateBinding BorderThickness}"
                                  Foreground="{TemplateBinding Foreground}"
                                  Header="{TemplateBinding Header}"
                                  HeaderTemplate="{TemplateBinding HeaderTemplate}"
                                  HeaderTemplateSelector="{TemplateBinding HeaderTemplateSelector}"
                                  HorizontalAlignment="Stretch"
                                  IsExpanded="{TemplateBinding IsExpanded}"
                                  Margin="{Binding Converter={StaticResource DoubleToThicknessConverter}, ConverterParameter='Left, Right, Bottom', RelativeSource={RelativeSource Self}, Path=(params:General.BoldPaddingValue), Mode=OneWay}"
                                  Padding="{TemplateBinding Padding}"
                                  Style="{StaticResource NonAnimatedExpanderStyle}">
                            <ItemsPresenter/>
                        </Expander>
                        <controls:BorderFix x:Name="Content"
                                Background="{TemplateBinding Background}"
                                BorderBrush="{TemplateBinding BorderBrush}"
                                BorderThickness="{TemplateBinding BorderThickness}"
                                Margin="{Binding Converter={StaticResource DoubleToThicknessConverter}, ConverterParameter='Left, Right, Bottom', RelativeSource={RelativeSource Self}, Path=(params:General.BoldPaddingValue), Mode=OneWay}"
                                Padding="{TemplateBinding Padding}"
                                Visibility="Collapsed">
                            <ContentControl Content="{TemplateBinding Header}"
                                                ContentTemplate="{TemplateBinding HeaderTemplate}"
                                                ContentTemplateSelector="{TemplateBinding HeaderTemplateSelector}"
                                                Foreground="{TemplateBinding Foreground}"
                                                HorizontalAlignment="Stretch"/>
                        </controls:BorderFix>
                    </StackPanel>
                    <ControlTemplate.Triggers>
                        <Trigger Property="HasItems" Value="False">
                            <Setter Property="Visibility" TargetName="Expander" Value="Collapsed"/>
                            <Setter Property="Visibility" TargetName="Content" Value="Visible"/>
                        </Trigger>
                        <Trigger Property="IsMouseOver" Value="True">
                            <Setter Property="Background" Value="{StaticResource ForegroundBrush}"/>
                            <Setter Property="BorderBrush" Value="{StaticResource ForegroundBrush}"/>
                            <Setter Property="Foreground" Value="{StaticResource BackgroundBrush}"/>
                        </Trigger>
                        <Trigger Property="IsSelected" Value="True">
                            <Setter Property="Background" Value="{StaticResource AccentBrush}"/>
                            <Setter Property="BorderBrush" Value="{StaticResource AccentBrush}"/>
                            <Setter Property="Foreground" Value="{StaticResource BackgroundBrush}"/>
                        </Trigger>
                        <Trigger Property="IsEnabled" Value="False">
                            <Setter Property="Background" Value="{StaticResource DisabledBrush}"/>
                            <Setter Property="BorderBrush" Value="{StaticResource DisabledBrush}"/>
                            <Setter Property="Foreground" Value="{StaticResource BackgroundBrush}"/>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
    
</ResourceDictionary>